package mao.leetcode.string.leetcode443;

public class Solution {

    public int compress(char[] chars) {
        int write=0,count=1;
        for (int i = 0; i < chars.length; i++) {
            if (i <chars.length-1 && chars[i] == chars[i+1]){ //注意边界
                count++;
            }else {
                chars[write]=chars[i];
                write++;
                if (count >=2){
                    for (char c:(count+"").toCharArray())  //数字到字符的转换
                        chars[write++]=c;
                }
                count=1;
            }
        }
        return write;
    }
}
